class WebSpecRunnerWorker < BackgrounDRb::Worker::RailsBase
  
  def do_work(id)
    selenium = Selenium::SeleniumDriver.new('localhost', 4444, '*firefox', 'http://www.google.com')
    selenium.start
    run = Run.find(id)
    run.update_attribute :status, 'running'
    run_commands(selenium, run.to_rselenese)
    run.update_attribute :status, 'finished'
  end

  private
  
  def run_commands(selenium, commands)
    commands.each do |cmd|
      next unless selenium.respond_to?(cmd[:command].to_sym)
      cmd_args = cmd[:arguments] || []
      selenium.send cmd[:command].to_sym, *cmd_args
    end
  end
  
end
WebSpecRunnerWorker.register
